package org.dinner.order.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

@Entity
@NamedQueries({
	@NamedQuery(name="User.list", query="from User"),
	@NamedQuery(name="User.getByLogin", query="from User u where u.login=:login")
})
@Table(name = "USERS")
public class User {
	
	@Id
	@GeneratedValue
	private int id;
	@Column(nullable = false)
	@NotEmpty
	private String firstName;
	@NotEmpty
	private String lastName;
	@Email
	@NotEmpty
	private String email;
	@Column(nullable = false)
	@Size(min=4, max=8)
	private String login;
	@Column(nullable = false)
	@Size(min=4, max=8)
	private String password;
	@ManyToOne
	@JoinColumn(name = "unit_id")
	private ShippingUnit unit;
	@ManyToOne
	@JoinColumn(name = "role_id", nullable = false)
	private Role role;
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public ShippingUnit getUnit() {
		return unit;
	}
	public void setUnit(ShippingUnit unit) {
		this.unit = unit;
	}
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	
	
}
